package cqu.mvc.model.utils;

// import org.eclipse.persistence.sessions.factories.SessionFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import cqu.mvc.model.domain.FileEntity;

/**
 * hibernate工具类
 */
public class HiberUtil {
    private static final SessionFactory sessionFatory; //初始化Hibernate,sessionFatory充当数据存储源的代理，并负责创建Session对象

    static{
        //获取hibernate.properties或hibernate.cfg.xml的配置信息
        final Configuration configuration = new Configuration();
        configuration.addAnnotatedClass( FileEntity.class );
        //创建sessionFactory
        sessionFatory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    }

    //从sessionFactory中获取session
    public static Session getSession(){
        return sessionFatory.openSession();
    }
}
